import { getLastOffset } from "element-plus/es/components/message/src/instance.mjs";
import { defineStore } from "pinia";

export interface Message {
  role: 'user' | 'system' | 'assistant';
  content: string;
}

export const useMessagesStore = defineStore("chat", {
  state: (): { messages: Message[] } => ({
    messages: [], // 修改为一个空数组
  }),
  actions: {
    addMessage(message: Message) {
      this.messages.push(message);
    },
    updateLastMessageContent(content: string) {
      if (this.messages.length > 0) {
        this.messages[this.messages.length - 1].content = content;
      }
    },
    clearMessages() {
      // 保留初始系统消息
      this.messages.splice(0);
      this.addMessage({
        role: 'system',
        content: '您好！我是讯飞星火AI助手，有什么可以帮您的？'
      })
    },
    getLastMessage() {
      return this.messages[this.messages.length - 1];
    },
  },
});